/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.

// CkeClusterSpec defines the desired state of CkeCluster
type CkeClusterSpec struct {
	Version           string             `json:"version,omitempty"`
	ClusterParameters CkeClusterPrameter `json:"cluster_parameters,omitempty"`
	Registry          CkeRegistry        `json:"registry,omitempty"`
	// deprecated, use cluster_vip replace
	ClusterVips       []CkeClusterVip   `json:"cluster_vips,omitempty"`
	ClusterVip        CkeClusterVip     `json:"cluster_vip,omitempty"`
	Etcd              CkeEtcd           `json:"etcd,omitempty"`
	Docker            CkeDocker         `json:"docker,omitempty"`
	Dns               CkeDns            `json:"dns,omitempty"`
	Plugins           []CkeAddons       `json:"plugins,omitempty"`
	Addons            []CkeAddons       `json:"addons,omitempty"`
	ExtraArgs         map[string]string `json:"extra_parameters,omitempty"`
	DockerPreconfiged []string          `json:"docker_preconfiged,omitempty"`
	AnsibleSshPort    int               `json:"ansible_ssh_port,omitempty"`
}

// CkeClusterStatus defines the observed state of CkeCluster
type CkeClusterStatus struct {
	Version            string   `json:"version,omitempty"`
	State              string   `json:"state,omitempty"`
	Reason             string   `json:"reason,omitempty"`
	Message            string   `json:"message,omitempty"`
	ActiveCKEPatch     string   `json:"activeCKEPatch,omitempty"`
	ActivePatchJob     string   `json:"activePatchJob,omitempty"`
	RunningAddons      []string `json:"runningAddons,omitempty"`
	Initialization     bool     `json:"initialization,omitempty"`
	CompletedCKEPatchs []string `json:"completedCKEPatchs,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.state"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="VERSION",type="string",JSONPath=".status.version"

// CkeCluster is the Schema for the ckeclusters API
type CkeCluster struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   CkeClusterSpec   `json:"spec,omitempty"`
	Status CkeClusterStatus `json:"status,omitempty"`
}

type CkeClusterPrameter struct {
	KubeServiceCidr        string `json:"kube_service_cidr,omitempty"`
	KubePodsCidr           string `json:"kube_pods_cidr,omitempty"`
	DefaultMasterMaxPods   int    `json:"default_master_max_pods,omitempty"`
	DefaultSlaveMaxPods    int    `json:"default_slave_max_pods,omitempty"`
	ClusterSize            int    `json:"cluster_size,omitempty"`
	ApiserverDomainName    string `json:"apiserver_domain_name,omitempty"`
	KubeletDataRoot        string `json:"kubelet_data_root,omitempty"`
	OverrideSystemHostname bool   `json:"override_system_hostname"`
	ImageManifestEnabled   bool   `json:"image_manifest_enabled"`
	OidcIssuerUrl          string `json:"oidc_issuer_url,omitempty"`
	KubeProxyMode          string `json:"kube_proxy_mode,omitempty"`
	// deprecated, use ntp_servers replace
	ExternalNtpServer []string `json:"external_ntp_server,omitempty"`
	NtpServers        []string `json:"ntp_servers,omitempty"`
}

type CkeRegistry struct {
	Ip     string `json:"ip,omitempty"`
	Port   int    `json:"port,omitempty"`
	Domain string `json:"domain,omitempty"`
}

type CkeClusterVip struct {
	Ip       string `json:"ip,omitempty"`
	RouterId int    `json:"router_id,omitempty"`
	// deprecated, auto get interface
	Interface string `json:"interface,omitempty"`
	// deprecated, only use apiserver vip
	IsApiserver bool `json:"is_apiserver,omitempty"`
}

type CkeDns struct {
	Type  string                 `json:"type,omitempty"`
	Hosts []CkeExternalDnsDomain `json:"hosts,omitempty"`
	// deprecated, use apiserver vip
	ExternalDns     []string `json:"external_dns,omitempty"`
	ExternalServers []string `json:"external_servers,omitempty"`
}

type CkeExternalDnsDomain struct {
	Ip   string   `json:"ip,omitempty"`
	Name []string `json:"name,omitempty"`
}

type CkeEtcd struct {
	HeartbeatInterval int `json:"heartbeat_interval,omitempty"`
	ElectionTimeout   int `json:"election_timeout,omitempty"`
}

type CkeDocker struct {
	DockerDataRoot string   `json:"docker_data_root,omitempty"`
	Registries     []string `json:"registries,omitempty"`
}

type CkeCalico struct {
	Mtu int `json:"mtu,omitempty"`
}

type CkeAddons struct {
	Name       string            `json:"name,omitempty"`
	Parameters map[string]string `json:"parameters,omitempty"`
}

// +kubebuilder:object:root=true

// CkeClusterList contains a list of CkeCluster
type CkeClusterList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []CkeCluster `json:"items"`
}

func init() {
	SchemeBuilder.Register(&CkeCluster{}, &CkeClusterList{})
}
